//
//  HJNewsCell.m
//  KaiChat
//
//  Created by lx on 2023/12/22.
//

#import "HJNewsCell.h"


@interface HJNewsCell()

@property (nonatomic, weak) UIImageView *coverImageView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *contentLabel;
@property (nonatomic, weak) UILabel *timeLabel;

@end


@implementation HJNewsCell



- (void)settingSubView {
    [super settingSubView];
    
    
    self.backgroundColor = UIColor.tj_F6F6F6Color;
    
    UILabel *timeLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_BEBDCAColor title:nil textAlignment:NSTextAlignmentLeft];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(56);
        make.top.offset(0);
        make.centerX.offset(0);
    }];
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.addCornerRadius(10);
    tj_contentView.clipsToBounds = YES;
    tj_contentView.backgroundColor = UIColor.whiteColor;
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(leftRightMargin);
        make.top.equalTo(timeLabel.mas_bottom);
        make.bottom.offset(0);
    }];
    
    UIImageView *coverImageView = [UIImageView addToView:tj_contentView];
    coverImageView.clipsToBounds = YES;
    coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    [coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(100);
    }];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(15);
        make.top.equalTo(coverImageView.mas_bottom).offset(15);
    }];
    
    UILabel *contentLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    contentLabel.numberOfLines = 2;
    contentLabel.attributedText = [contentLabel.text titleMargin:3 alignment:NSTextAlignmentLeft];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(15);
        make.top.equalTo(titleLabel.mas_bottom).offset(8);
    }];
    
    _timeLabel = timeLabel;
    _contentLabel = contentLabel;
    _titleLabel = titleLabel;
    _coverImageView = coverImageView;
}

- (void)setModel:(HJNewsModel *)model {
    _model = model;
    
    [_coverImageView tj_setImageWithUrl:model.coverUrl placeholderImage:[UIImage imageNamed:@"bigLoad"]];
    _titleLabel.text = model.title;
    _contentLabel.text = model.desc;
    _timeLabel.text = [[NSDate dateWithTimeIntervalSince1970:[model.timestamp integerValue] / 1000] stringWithFormat:@"yyyy/MM/dd HH:mm"];
}

@end
